package codingforgreat.lchot150;

public class Lc152 {
    public int maxProduct(int[] nums) {
        if(nums == null || nums.length == 0){
            return 0;
        }
        int premax = nums[0];
        int premin = nums[0];
        int ans = nums[0];
        for(int i = 1;i < nums.length;i++){
            int cur = nums[i];
            int p1 = premax * cur;
            int p2 = premin * cur;
            int curmax = Math.max(cur,Math.max(p1,p2));
            int curmin = Math.min(cur,Math.min(p1,p2));
            ans = Math.max(ans,curmax);
            premax = curmax;
            premin = curmin;
        }
        return ans;
    }
}
